﻿using BaseData.DomainLib.AggregatesModel.CalculateUnitAggregate;
using Microsoft.EntityFrameworkCore;
using Swimj.DomainLib.SeedWork;

namespace BaseData.InfrastructureLib.Repositories
{
    public class CalculateUnitRepository : ICalculateUnitRepository
    {
        private readonly BaseDataDbContext _dbContext;

        public IUnitOfWork UnitOfWork => _dbContext;

        public CalculateUnitRepository(BaseDataDbContext dbContext)
        {
            this._dbContext = dbContext;
        }

        public CalculateUnit Add(CalculateUnit unit)
        {
            return _dbContext.Units.Add(unit).Entity;
        }

        public async Task<CalculateUnit?> Get(int id)
        {
            return await _dbContext.Units.FirstOrDefaultAsync(u => u.Id == id);
        }
    }
}
